CROSS_COMPILE = arm-hisiv100nptl-linux-

AR		= $(CROSS_COMPILE)ar
AS		= $(CROSS_COMPILE)as
CC		= $(CROSS_COMPILE)gcc
CPP		= $(CROSS_COMPILE)g++
LD		= $(CROSS_COMPILE)ld
NM		= $(CROSS_COMPILE)nm
OBJCOPY	= $(CROSS_COMPILE)objcopy
OBJDUMP	= $(CROSS_COMPILE)objdump
RANLIB	= $(CROSS_COMPILE)ranlib
SIZE	= $(CROSS_COMPILE)size
STRIP	= $(CROSS_COMPILE)strip

TOPDIR=..
C_INCLUDES=
SRCS=
CFLAGS=

C_INCLUDES+=-I$(TOPDIR)/inc/
CFLAGS +=  -lpthread $(C_INCLUDES)
CFLAGS += -g -rdynamic -Werror
#CFLAGS += -DMEMWATCH -DMW_PTHREADS 


SRCS+=$(wildcard ./*.c)

OBJECTS=$(SRCS:.c=.o)

MEMWATCH_LIB:=memwatch.a

$(MEMWATCH_LIB):$(OBJECTS)
	@echo "  ***Creating library :$@"
	@$(AR) crus ./$@ $^
	@cp ./$@ $(TOPDIR)
	@echo "  *** Done"
	@echo

-include $(OBJECTS:.o=.d)
%.d:%.c
	@set -e; rm -f $@; \
		$(CC) -MM $(C_INCLUDES) $< > $@.$$$$; \
		sed 's,\($*\)\.o[ : ]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
		rm -f $@.$$$$

.PHONY:clean
clean:
	@-rm main -f *.o *.d *.d.* *.a
